using System.Text;
using System;

namespace Net
{
    class ProcedureResultParser
    {
        private ObjectState objectState;
        private byte packageIdentifier;
        public ProcedureResultParser(ObjectState objectState)
        {
            this.objectState = objectState;
            packageIdentifier = objectState.buffer[4];
        }

        public void ParseProcedurePackage()
        {
            string code = Encoding.ASCII.GetString(objectState.buffer, objectState.offset + 5, 4);
            switch (code)
            {
				case "2001":
					AffectedRowsReach();
					break;
				case "2003":
					AffectedRowsReach();
					break;
				case "2005":
					DBDataReach();
					break;
				case "2007":
					DBDataReach();
					break;
				case "2009":
					DBDataReach();
					break;
				case "2011":
					DBDataReach();
					break;
				case "2013":
					AffectedRowsReach();
					break;
				case "2015":
					AffectedRowsReach();
					break;
				case "2017":
					AffectedRowsReach();
					break;
				case "2019":
					AffectedRowsReach();
					break;
				case "2021":
					DBDataReach();
					break;
				case "2023":
					DBDataReach();
					break;
				case "2025":
					AffectedRowsReach();
					break;
				case "2027":
					AffectedRowsReach();
					break;
				case "2029":
					DBDataReach();
					break;
				case "2031":
					DBDataReach();
					break;
				case "2033":
					AffectedRowsReach();
					break;
				case "2035":
					DBDataReach();
					break;

                default:
                    break;
            }
        }

        private void DBDataReach()
        {
            NetCallback netCallback = NetService.callbackMap[packageIdentifier];
            netCallback.AsyncObject = ByteArrayParser.ByteArrayToObject(objectState.buffer, objectState.offset + 9, objectState.packageLength - 9);
            netCallback.Execute();
        }

		private void AffectedRowsReach()
		{
			NetCallback netCallback = NetService.callbackMap[packageIdentifier];
			netCallback.AsyncObject = Convert.ToInt32(Encoding.Unicode.GetString(objectState.buffer, objectState.offset + 9, objectState.packageLength - 9));
            netCallback.Execute();
		}
    }
}
